package originatorV3;

import originatorV2.SelectionnerOriginator;
import caretakerV3.GestionDefaire;

import command.Command;

import mementoV2.Memento;
import mementoV2.SelectionnerMemento;
import mementoV3.MementoV3;
import mementoV3.SelectionnerMementoV3;

public class SelectionnerOriginatorV3 implements OriginatorV3 {

	private GestionDefaire _gestion;
	private Command _selection;
	private int debutSelection;
	private int finSelection;
	

	public SelectionnerOriginatorV3(GestionDefaire gestion, Command command) {
		this._gestion = gestion;
		this._selection = command;
	}

	@Override
	public void execute() {
		((SelectionnerOriginator) this._selection).execute();
		int debut = ((SelectionnerOriginator) this._selection).getDebutSelection();
		int fin = ((SelectionnerOriginator) this._selection).getFinSelection();
		
		MementoV3 m = new SelectionnerMementoV3(this, debut, fin);
		
		this._gestion.sauvegarder(m);
	}

	@Override
	public void setMemento(MementoV3 m) {
		debutSelection = ((SelectionnerMementoV3) m).get_debut();
		finSelection = ((SelectionnerMementoV3) m).get_fin();
		Memento mem = new SelectionnerMemento(debutSelection, finSelection, (SelectionnerOriginator)_selection);
		
		((SelectionnerOriginator)_selection).setMemento(mem);
		System.out.println("V3 deb \t"+debutSelection+"\tfin\t"+finSelection);
	}

}
